from flask import Flask,render_template
from app_config import app_Config, SmtpServerConfig
from auth import auth_init
from auth.routes import auth_bp, page_bp 
from flask_wtf.csrf import generate_csrf


def create_app(config_class=app_Config):
    app = Flask(__name__)
    for i in config_class:
        app.config.from_object(i)
    auth_init(app)
    
    # 注册蓝图
    app.register_blueprint(auth_bp)  # API路由
    app.register_blueprint(page_bp)   # 页面路由
    
    
    @app.context_processor
    def inject_csrf_token():
        return dict(csrf_token=generate_csrf())

    # 添加主页路由
    @app.route('/')
    def home():
        return render_template('base.html')
    
    return app

if __name__ == '__main__':
    app = create_app(config_class=[app_Config, SmtpServerConfig])
    app.run(debug=True)  